
<!doctype html>
<html lang="en" class="no-js">
  <head>
    
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width,initial-scale=1">
      
      
      
        <link rel="canonical" href="https://daptin.github.io/daptin/state/machines/">
      
      <link rel="icon" href="../../images/theme-favicon.png">
      <meta name="generator" content="mkdocs-1.2.3, mkdocs-material-8.2.4">
    
    
      
        <title>State tracking - Daptin</title>
      
    
    
      <link rel="stylesheet" href="../../assets/stylesheets/main.2d9f7617.min.css">
      
        
        <link rel="stylesheet" href="../../assets/stylesheets/palette.e6a45f82.min.css">
        
      
    
    
    
      
        
        
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
        <style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
      
    
    
      <link rel="stylesheet" href="../../css/theme_extra.css">
    
    <script>__md_scope=new URL("../..",location),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
    
      

    
    
  </head>
  
  
    
    
    
    
    
    <body dir="ltr" data-md-color-scheme="" data-md-color-primary="none" data-md-color-accent="none">
  
    
    
    <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
    <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
    <label class="md-overlay" for="__drawer"></label>
    <div data-md-component="skip">
      
        
        <a href="#state-tracking" class="md-skip">
          Skip to content
        </a>
      
    </div>
    <div data-md-component="announce">
      
    </div>
    
    
      

<header class="md-header" data-md-component="header">
  <nav class="md-header__inner md-grid" aria-label="Header">
    <a href="../.." title="Daptin" class="md-header__button md-logo" aria-label="Daptin" data-md-component="logo">
      
  <img src="../../images/theme-logo.png" alt="logo">

    </a>
    <label class="md-header__button md-icon" for="__drawer">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2z"/></svg>
    </label>
    <div class="md-header__title" data-md-component="header-title">
      <div class="md-header__ellipsis">
        <div class="md-header__topic">
          <span class="md-ellipsis">
            Daptin
          </span>
        </div>
        <div class="md-header__topic" data-md-component="header-topic">
          <span class="md-ellipsis">
            
              State tracking
            
          </span>
        </div>
      </div>
    </div>
    
    
    
      <label class="md-header__button md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg>
      </label>
      <div class="md-search" data-md-component="search" role="dialog">
  <label class="md-search__overlay" for="__search"></label>
  <div class="md-search__inner" role="search">
    <form class="md-search__form" name="search">
      <input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
      <label class="md-search__icon md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
      </label>
      <nav class="md-search__options" aria-label="Search">
        
        <button type="reset" class="md-search__icon md-icon" aria-label="Clear" tabindex="-1">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg>
        </button>
      </nav>
      
    </form>
    <div class="md-search__output">
      <div class="md-search__scrollwrap" data-md-scrollfix>
        <div class="md-search-result" data-md-component="search-result">
          <div class="md-search-result__meta">
            Initializing search
          </div>
          <ol class="md-search-result__list"></ol>
        </div>
      </div>
    </div>
  </div>
</div>
    
    
  </nav>
  
</header>
    
    <div class="md-container" data-md-component="container">
      
      
        
          
        
      
      <main class="md-main" data-md-component="main">
        <div class="md-main__inner md-grid">
          
            
              
              <div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    


<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
  <label class="md-nav__title" for="__drawer">
    <a href="../.." title="Daptin" class="md-nav__button md-logo" aria-label="Daptin" data-md-component="logo">
      
  <img src="../../images/theme-logo.png" alt="logo">

    </a>
    Daptin
  </label>
  
  <ul class="md-nav__list" data-md-scrollfix>
    
      
      
      

  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
        <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_1" type="checkbox" id="__nav_1" >
      
      
      
      
        <label class="md-nav__link" for="__nav_1">
          Introduction
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" aria-label="Introduction" data-md-level="1">
        <label class="md-nav__title" for="__nav_1">
          <span class="md-nav__icon md-icon"></span>
          Introduction
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../.." class="md-nav__link">
        About
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../faq.md" class="md-nav__link">
        FAQs
      </a>
    </li>
  

            
          
            
              
  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
        <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_1_3" type="checkbox" id="__nav_1_3" >
      
      
      
      
        <label class="md-nav__link" for="__nav_1_3">
          How to use
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" aria-label="How to use" data-md-level="2">
        <label class="md-nav__title" for="__nav_1_3">
          <span class="md-nav__icon md-icon"></span>
          How to use
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../setting-up/installation/" class="md-nav__link">
        Download and Deploy
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../setting-up/settingup/" class="md-nav__link">
        Accessing the web dashboard
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
    
  
  
    
    <li class="md-nav__item md-nav__item--active md-nav__item--nested">
      
      
        <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_2" type="checkbox" id="__nav_2" checked>
      
      
      
      
        <label class="md-nav__link" for="__nav_2">
          Documentation
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" aria-label="Documentation" data-md-level="1">
        <label class="md-nav__title" for="__nav_2">
          <span class="md-nav__icon md-icon"></span>
          Documentation
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
        <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_2_1" type="checkbox" id="__nav_2_1" >
      
      
      
      
        <label class="md-nav__link" for="__nav_2_1">
          User management
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" aria-label="User management" data-md-level="2">
        <label class="md-nav__title" for="__nav_2_1">
          <span class="md-nav__icon md-icon"></span>
          User management
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../user-management/new-users/" class="md-nav__link">
        New User
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../user-management/access/" class="md-nav__link">
        Access Permissions
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../user-management/signin/" class="md-nav__link">
        Sign in API
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../setting-up/data_modeling/" class="md-nav__link">
        Data model
      </a>
    </li>
  

            
          
            
              
  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
        <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_2_3" type="checkbox" id="__nav_2_3" >
      
      
      
      
        <label class="md-nav__link" for="__nav_2_3">
          HTTP JSON API
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" aria-label="HTTP JSON API" data-md-level="2">
        <label class="md-nav__title" for="__nav_2_3">
          <span class="md-nav__icon md-icon"></span>
          HTTP JSON API
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../apis/crud/" class="md-nav__link">
        CRUD API
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../apis/crud/" class="md-nav__link">
        Action API
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../apis/crud/" class="md-nav__link">
        Relation API
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../apis/crud/" class="md-nav__link">
        Aggregation API
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../apis/crud/" class="md-nav__link">
        State machine API
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../apis/crud/" class="md-nav__link">
        Metadata API
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

            
          
            
              
  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
        <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_2_4" type="checkbox" id="__nav_2_4" >
      
      
      
      
        <label class="md-nav__link" for="__nav_2_4">
          Actions
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" aria-label="Actions" data-md-level="2">
        <label class="md-nav__title" for="__nav_2_4">
          <span class="md-nav__icon md-icon"></span>
          Actions
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../actions/actions/" class="md-nav__link">
        What are actions
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../actions/default_actions/" class="md-nav__link">
        Actions list
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../actions/outcomes/" class="md-nav__link">
        Action OutComes
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../actions/examples/" class="md-nav__link">
        Examples
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../features/enable-graphql/" class="md-nav__link">
        GraphQL
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../features/enable-data-auditing/" class="md-nav__link">
        Data Auditing
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../features/enable-multilingual-table/" class="md-nav__link">
        Multilingual Table
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../features/enable-smtp-imap/" class="md-nav__link">
        SMTP/IMPS server
      </a>
    </li>
  

            
          
            
              
  
  
    
  
  
    <li class="md-nav__item md-nav__item--active">
      
      <input class="md-nav__toggle md-toggle" data-md-toggle="toc" type="checkbox" id="__toc">
      
      
        
      
      
        <label class="md-nav__link md-nav__link--active" for="__toc">
          State tracking
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <a href="./" class="md-nav__link md-nav__link--active">
        State tracking
      </a>
      
        

<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
  
  
  
    
  
  
    <label class="md-nav__title" for="__toc">
      <span class="md-nav__icon md-icon"></span>
      Table of contents
    </label>
    <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
      
        <li class="md-nav__item">
  <a href="#defining-a-state-machine" class="md-nav__link">
    Defining a state machine
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#state-machine" class="md-nav__link">
    State machine
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#rest-api" class="md-nav__link">
    REST API
  </a>
  
    <nav class="md-nav" aria-label="REST API">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#start-tracking-an-object-by-state-machine-reference-id" class="md-nav__link">
    Start tracking an object by state machine reference id
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#trigger-an-event-by-name-in-the-state-of-an-object" class="md-nav__link">
    Trigger an event by name in the state of an object
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#enabling-state-tracking-for-entity" class="md-nav__link">
    Enabling state tracking for entity
  </a>
  
</li>
      
    </ul>
  
</nav>
      
    </li>
  

            
          
            
              
  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
        <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_2_10" type="checkbox" id="__nav_2_10" >
      
      
      
      
        <label class="md-nav__link" for="__nav_2_10">
          OAuth
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" aria-label="OAuth" data-md-level="2">
        <label class="md-nav__title" for="__nav_2_10">
          <span class="md-nav__icon md-icon"></span>
          OAuth
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../extend/oauth_connection/" class="md-nav__link">
        OAuth Connections
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../extend/oauth_token/" class="md-nav__link">
        OAuth Tokens
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../integrations/overview/" class="md-nav__link">
        3rd party API Integrations
      </a>
    </li>
  

            
          
            
              
  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
        <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_2_12" type="checkbox" id="__nav_2_12" >
      
      
      
      
        <label class="md-nav__link" for="__nav_2_12">
          Cloud store
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" aria-label="Cloud store" data-md-level="2">
        <label class="md-nav__title" for="__nav_2_12">
          <span class="md-nav__icon md-icon"></span>
          Cloud store
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../cloudstore/" class="md-nav__link">
        Cloud store
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../cloudstore/cloudstore/" class="md-nav__link">
        Available cloud stores
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../cloudstore/cloudstore/" class="md-nav__link">
        Asset columns
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../cloudstore/cloudstore/" class="md-nav__link">
        Asset columns
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../cloudstore/sites/" class="md-nav__link">
        Sites
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../cloudstore/assetcolumns/" class="md-nav__link">
        Cloud store backed asset columns
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../websockets/websocket/" class="md-nav__link">
        Websockets
      </a>
    </li>
  

            
          
            
              
  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
        <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_2_15" type="checkbox" id="__nav_2_15" >
      
      
      
      
        <label class="md-nav__link" for="__nav_2_15">
          Sub-sites
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" aria-label="Sub-sites" data-md-level="2">
        <label class="md-nav__title" for="__nav_2_15">
          <span class="md-nav__icon md-icon"></span>
          Sub-sites
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../subsite/subsite/" class="md-nav__link">
        Creating a subsite
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../subsite/grapes/" class="md-nav__link">
        Live editing a subsite
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../subsite/basic_auth/" class="md-nav__link">
        Basic Authentication
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

            
          
            
              
  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
        <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_2_16" type="checkbox" id="__nav_2_16" >
      
      
      
      
        <label class="md-nav__link" for="__nav_2_16">
          Internal Documents
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" aria-label="Internal Documents" data-md-level="2">
        <label class="md-nav__title" for="__nav_2_16">
          <span class="md-nav__icon md-icon"></span>
          Internal Documents
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../data-modeling/data_storage/" class="md-nav__link">
        Data store format
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../extend/data_exchange/" class="md-nav__link">
        Data exchange and sync
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../streams/streams/" class="md-nav__link">
        Data streams
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../setting-up/configurations/" class="md-nav__link">
        Global Configuration
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
  </ul>
</nav>
                  </div>
                </div>
              </div>
            
            
              
              <div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    

<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
  
  
  
    
  
  
    <label class="md-nav__title" for="__toc">
      <span class="md-nav__icon md-icon"></span>
      Table of contents
    </label>
    <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
      
        <li class="md-nav__item">
  <a href="#defining-a-state-machine" class="md-nav__link">
    Defining a state machine
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#state-machine" class="md-nav__link">
    State machine
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#rest-api" class="md-nav__link">
    REST API
  </a>
  
    <nav class="md-nav" aria-label="REST API">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#start-tracking-an-object-by-state-machine-reference-id" class="md-nav__link">
    Start tracking an object by state machine reference id
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#trigger-an-event-by-name-in-the-state-of-an-object" class="md-nav__link">
    Trigger an event by name in the state of an object
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#enabling-state-tracking-for-entity" class="md-nav__link">
    Enabling state tracking for entity
  </a>
  
</li>
      
    </ul>
  
</nav>
                  </div>
                </div>
              </div>
            
          
          <div class="md-content" data-md-component="content">
            <article class="md-content__inner md-typeset">
              
                


<h1 id="state-tracking">State tracking</h1>
<p>State of an object can help you tracing any sort of progress while making sure you maintain the consistence of the state. For eg, you might want to track the status of a "blog post" in terms of "draft"/"edited"/"published" which pre-defined endpoints defining the flow of states.</p>
<p>Tracking the status of things is one of the most common operation in most business flows. Daptin has a native support for state tracking and allows a lot of convienent features.</p>
<h2 id="defining-a-state-machine">Defining a state machine</h2>
<p>Define a state machine in YAML or JSON as follows:</p>
<div class="admonition example">
<p class="admonition-title">State machine description YAML</p>
<div class="highlight"><pre><span></span><code><span class="nt">StateMachineDescriptions</span><span class="p">:</span><span class="w"></span>
<span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">Name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">task_status</span><span class="w"></span>
<span class="w">  </span><span class="nt">Label</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">Task Status</span><span class="w"></span>
<span class="w">  </span><span class="nt">InitialState</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">to_be_done</span><span class="w"></span>
<span class="w">  </span><span class="nt">Events</span><span class="p">:</span><span class="w"></span>
<span class="w">  </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">Name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">start</span><span class="w"></span>
<span class="w">    </span><span class="nt">Label</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">Start</span><span class="w"></span>
<span class="w">    </span><span class="nt">Src</span><span class="p">:</span><span class="w"></span>
<span class="w">    </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">to_be_done</span><span class="w"></span>
<span class="w">    </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">delayed</span><span class="w"></span>
<span class="w">    </span><span class="nt">Dst</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">started</span><span class="w"></span>
<span class="w">  </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">Name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">delayed</span><span class="w"></span>
<span class="w">    </span><span class="nt">Label</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">Unable to pick up</span><span class="w"></span>
<span class="w">    </span><span class="nt">Src</span><span class="p">:</span><span class="w"></span>
<span class="w">    </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">to_be_done</span><span class="w"></span>
<span class="w">    </span><span class="nt">Dst</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">delayed</span><span class="w"></span>
<span class="w">  </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">Name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">ongoing</span><span class="w"></span>
<span class="w">    </span><span class="nt">Label</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">Record progress</span><span class="w"></span>
<span class="w">    </span><span class="nt">Src</span><span class="p">:</span><span class="w"></span>
<span class="w">    </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">started</span><span class="w"></span>
<span class="w">    </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">ongoing</span><span class="w"></span>
<span class="w">    </span><span class="nt">Dst</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">ongoing</span><span class="w"></span>
<span class="w">  </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">Name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">interrupted</span><span class="w"></span>
<span class="w">    </span><span class="nt">Label</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">Interrupted</span><span class="w"></span>
<span class="w">    </span><span class="nt">Src</span><span class="p">:</span><span class="w"></span>
<span class="w">    </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">started</span><span class="w"></span>
<span class="w">    </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">ongoing</span><span class="w"></span>
<span class="w">    </span><span class="nt">Dst</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">interrupted</span><span class="w"></span>
<span class="w">  </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">Name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">resume</span><span class="w"></span>
<span class="w">    </span><span class="nt">Label</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">Resume from interruption</span><span class="w"></span>
<span class="w">    </span><span class="nt">Src</span><span class="p">:</span><span class="w"></span>
<span class="w">    </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">interrupted</span><span class="w"></span>
<span class="w">    </span><span class="nt">Dst</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">ongoing</span><span class="w"></span>
<span class="w">  </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">Name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">completed</span><span class="w"></span>
<span class="w">    </span><span class="nt">Label</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">Mark as completed</span><span class="w"></span>
<span class="w">    </span><span class="nt">Src</span><span class="p">:</span><span class="w"></span>
<span class="w">    </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">ongoing</span><span class="w"></span>
<span class="w">    </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">started</span><span class="w"></span>
<span class="w">    </span><span class="nt">Dst</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">completed</span><span class="w"></span>
</code></pre></div>
</div>
<p>Using state machine descriptions with daptin expose couple of super useful apis to manage state based data.</p>
<p>Enabling <code>task_status</code> state machine on <code>todo</code> entity will expose the following APIs</p>
<div class="highlight"><pre><span></span><code>POST /track/start/:stateMachineId <span class="o">{</span><span class="s2">&quot;typeName&quot;</span>: <span class="s2">&quot;todo&quot;</span>, <span class="s2">&quot;referenceId&quot;</span>: <span class="s2">&quot;objectId&quot;</span><span class="o">}</span> <span class="c1"># Start tracking a particular object by id</span>
</code></pre></div>
<p>This returns a state machine id.</p>
<div class="highlight"><pre><span></span><code>POST /track/event/:typename/:objectStateMachineId/:eventName <span class="o">{}</span> <span class="c1"># Trigger event on current state</span>
</code></pre></div>
<p>This either moves the <code>object state</code> to next state, or fails on invalid event name.</p>
<h2 id="state-machine">State machine</h2>
<p>A state machine is a description of "states" which the object can be in, and list of all valid transitions from one state to another. Let us begin with an example:</p>
<p>The following JSON defines a state machine which has (a hypothetical state machine for tracking todos):</p>
<ul>
<li>Initial state: to_be_done</li>
<li>List of valid states: to_be_done, delayed, started, ongoing, interrupted, completed</li>
<li>List of valid transitions, giving name to each event</li>
</ul>
<div class="highlight"><pre><span></span><code><span class="w">        </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="nt">&quot;Name&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;task_status&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">        </span><span class="nt">&quot;Label&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;Task Status&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">        </span><span class="nt">&quot;InitialState&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;to_be_done&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">        </span><span class="nt">&quot;Events&quot;</span><span class="p">:</span><span class="w"> </span><span class="p">[{</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Name&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;start&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Label&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;Start&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Src&quot;</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w"></span>
<span class="w">                    </span><span class="s2">&quot;to_be_done&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                    </span><span class="s2">&quot;delayed&quot;</span><span class="w"></span>
<span class="w">                </span><span class="p">],</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Dst&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;started&quot;</span><span class="w"></span>
<span class="w">            </span><span class="p">},</span><span class="w"></span>
<span class="w">            </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Name&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;delayed&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Label&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;Unable to pick up&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Src&quot;</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w"></span>
<span class="w">                    </span><span class="s2">&quot;to_be_done&quot;</span><span class="w"></span>
<span class="w">                </span><span class="p">],</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Dst&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;delayed&quot;</span><span class="w"></span>
<span class="w">            </span><span class="p">},</span><span class="w"></span>
<span class="w">            </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Name&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;ongoing&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Label&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;Record progress&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Src&quot;</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w"></span>
<span class="w">                    </span><span class="s2">&quot;started&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                    </span><span class="s2">&quot;ongoing&quot;</span><span class="w"></span>
<span class="w">                </span><span class="p">],</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Dst&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;ongoing&quot;</span><span class="w"></span>
<span class="w">            </span><span class="p">},</span><span class="w"></span>
<span class="w">            </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Name&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;interrupted&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Label&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;Interrupted&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Src&quot;</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w"></span>
<span class="w">                    </span><span class="s2">&quot;started&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                    </span><span class="s2">&quot;ongoing&quot;</span><span class="w"></span>
<span class="w">                </span><span class="p">],</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Dst&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;interrupted&quot;</span><span class="w"></span>
<span class="w">            </span><span class="p">},</span><span class="w"></span>
<span class="w">            </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Name&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;resume&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Label&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;Resume from interruption&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Src&quot;</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w"></span>
<span class="w">                    </span><span class="s2">&quot;interrupted&quot;</span><span class="w"></span>
<span class="w">                </span><span class="p">],</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Dst&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;ongoing&quot;</span><span class="w"></span>
<span class="w">            </span><span class="p">},</span><span class="w"></span>
<span class="w">            </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Name&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;completed&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Label&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;Mark as completed&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Src&quot;</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w"></span>
<span class="w">                    </span><span class="s2">&quot;ongoing&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                    </span><span class="s2">&quot;started&quot;</span><span class="w"></span>
<span class="w">                </span><span class="p">],</span><span class="w"></span>
<span class="w">                </span><span class="nt">&quot;Dst&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;completed&quot;</span><span class="w"></span>
<span class="w">            </span><span class="p">}</span><span class="w"></span>
<span class="w">        </span><span class="p">]</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>State machines can be uploaded to Daptin just like entities and actions. A JSON/YAML file with a <code>StateMachineDescriptions</code> top level key can contain an array of state machine descriptions.</p>
<h2 id="rest-api">REST API</h2>
<h3 id="start-tracking-an-object-by-state-machine-reference-id">Start tracking an object by state machine reference id</h3>
<p>Request
<div class="highlight"><pre><span></span><code>    POST  /track/start/:stateMachineId
    {&quot;typeName&quot;: &lt;entityTypeName&gt;, &quot;referenceId&quot;: &lt;ReferenceIdOfTheObject&gt; }
</code></pre></div></p>
<p>Response
<div class="highlight"><pre><span></span><code>        &quot;current_state&quot;: &lt;InitialStateOfTheStateMachine&gt;
        &quot;&lt;typename&gt;_smd&quot;: &lt;ObjectStateInstanceReferenceId&gt;
        &quot;is_state_of_&lt;typename&gt;&quot; = &lt;ObjectInstanceId&gt;
        &quot;permission&quot;: &lt;AuthPermission&gt;
</code></pre></div></p>
<h3 id="trigger-an-event-by-name-in-the-state-of-an-object">Trigger an event by name in the state of an object</h3>
<p><div class="highlight"><pre><span></span><code>    POST  /track/event/:typename/:ObjectStateInstanceReferenceId/:eventName
</code></pre></div>
Response
<div class="highlight"><pre><span></span><code>        &quot;current_state&quot;: &lt;NewStateAfterEvent&gt;
        &quot;&lt;typename&gt;_smd&quot;: &lt;ObjectStateInstanceReferenceId&gt;
        &quot;is_state_of_&lt;typename&gt;&quot; = &lt;ObjectInstanceId&gt;
</code></pre></div></p>
<h2 id="enabling-state-tracking-for-entity">Enabling state tracking for entity</h2>
<p>Begin with marking an entity as trackable. To do this,</p>
<ul>
<li>
<p>go to the world tables page and edit the an entity</p>
</li>
<li>
<p>Check the "Is state tracking enabled" checkbox</p>
</li>
</ul>
<p>This "is_state_tracking_enabled" options tells daptin to create the associated state table for the entity. Even though we have not yet specified which state machines are available for this entity.</p>
<p>To make a state machine available for an entity, go to the "SMD" tab of this entity on the same page and add the state machine by searching it by name and adding it.</p>
<p>It would not make a lot of sense if the above state machine was allowed for all type of entities.</p>

              
            </article>
          </div>
        </div>
        
      </main>
      
        <footer class="md-footer">
  
    <nav class="md-footer__inner md-grid" aria-label="Footer">
      
        
        <a href="../../features/enable-smtp-imap/" class="md-footer__link md-footer__link--prev" aria-label="Previous: SMTP/IMPS server" rel="prev">
          <div class="md-footer__button md-icon">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
          </div>
          <div class="md-footer__title">
            <div class="md-ellipsis">
              <span class="md-footer__direction">
                Previous
              </span>
              SMTP/IMPS server
            </div>
          </div>
        </a>
      
      
        
        <a href="../../extend/oauth_connection/" class="md-footer__link md-footer__link--next" aria-label="Next: OAuth Connections" rel="next">
          <div class="md-footer__title">
            <div class="md-ellipsis">
              <span class="md-footer__direction">
                Next
              </span>
              OAuth Connections
            </div>
          </div>
          <div class="md-footer__button md-icon">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 11v2h12l-5.5 5.5 1.42 1.42L19.84 12l-7.92-7.92L10.5 5.5 16 11H4z"/></svg>
          </div>
        </a>
      
    </nav>
  
  <div class="md-footer-meta md-typeset">
    <div class="md-footer-meta__inner md-grid">
      <div class="md-copyright">
  
  
    Made with
    <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
      Material for MkDocs
    </a>
  
</div>
      
    </div>
  </div>
</footer>
      
    </div>
    <div class="md-dialog" data-md-component="dialog">
      <div class="md-dialog__inner md-typeset"></div>
    </div>
    <script id="__config" type="application/json">{"base": "../..", "features": [], "translations": {"clipboard.copy": "Copy to clipboard", "clipboard.copied": "Copied to clipboard", "search.config.lang": "en", "search.config.pipeline": "trimmer, stopWordFilter", "search.config.separator": "[\\s\\-]+", "search.placeholder": "Search", "search.result.placeholder": "Type to start searching", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.term.missing": "Missing", "select.version.title": "Select version"}, "search": "../../assets/javascripts/workers/search.bd0b6b67.min.js"}</script>
    
    
      <script src="../../assets/javascripts/bundle.5413a266.min.js"></script>
      
    
  </body>
</html>